<?php

class Application_Model_DbTable_Order extends Zend_Db_Table_Abstract
{

    protected $_name = 'orders';

    //Cấu hình phân trang
    public function fetchPaginatorAdapter($filters=array(), $sortField = null, $sortType="asc")
    {
        $select = $this->select();
        //filter
        if(count($filters)>0)
        {
            
            foreach($filters as $field=>$filter)
            {
                if(!empty($filter) && !empty($field))
                {
                    if(is_string($filter))
                    {                      
                        $select->where("$field LIKE '%$filter%'");
                        if($field=="name")
                        {
                             $select->orWhere("fullname LIKE '%$filter%'");
                        }
                    }
                    else
                    {  
                        $select->where("$field=?", $filter);
                    }
                }               
            }
        }
        //sort
        if(null != $sortField)
        {
            $select->order($sortField." ".$sortType);
        }
        
        $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
        return $adapter;
    }
}//end class Application_Model_DbTable_Order